package com.leon.alishop.core.config.impl;

import java.util.List;

import com.leon.alishop.core.config.AlishopConfig;
import com.leon.alishop.core.enumeration.WebConfigTypeEnum;
import com.leon.alishop.dao.WebConfigDao;
import com.leon.alishop.model.WebConfig;

public class AlishopConfigImpl extends AlishopConfig{

	@Override
	public Integer getLastCrawlProviderId() {
		List<WebConfig> webConfigList = webConfigDao.selectByType(WebConfigTypeEnum.LAST_CRAWL_PROVIDER_ID.ordinal());
		if(webConfigList != null){
			try {
				return Integer.valueOf(webConfigList.get(0).getValue());
			} catch (Exception e) {
			}
		}
		return null;
	}
	
	@Override
	public synchronized void setLastCrawlProviderId(Integer providerId) {
		List<WebConfig> webConfigList = webConfigDao.selectByType(WebConfigTypeEnum.LAST_CRAWL_PROVIDER_ID.ordinal());
		WebConfig wc = new WebConfig();
		wc.setValue(Integer.toString(providerId));
		if(webConfigList != null && webConfigList.size()>0){
			wc.setId(webConfigList.get(0).getId());
			webConfigDao.updateByIdSelective(wc);
		}else{
			wc.setType(WebConfigTypeEnum.LAST_CRAWL_PROVIDER_ID.ordinal());
			webConfigDao.insertSelective(wc);
		}
	}
	
	private WebConfigDao webConfigDao;

	public void setWebConfigDao(WebConfigDao webConfigDao) {
		this.webConfigDao = webConfigDao;
	}

	
	
}
